package com.winit.flow.repository;

import com.winit.flow.model.VersionHistory;
import com.winit.flow.model.VersionHistoryId;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface FlowVersionHistoryRepository extends CrudRepository<VersionHistory, VersionHistoryId> {
    VersionHistory findFirstByTypeAndReqIdAndRelationIdOrderByCreateTimeDesc(String type, String reqId, String relationId);
    List<VersionHistory> findByReqIdAndRelationIdAndType(String reqId, String relationId, String type);
    @Query(value = "select * from matrix_version_history where relation_id = ?1 AND req_id = ?2 AND type = ?3 order by create_time DESC limit 0, 1", nativeQuery = true)
    VersionHistory findLatestVersionByRelationIdAndReqIdAndType(String relationId, String reqId, String type);



    @Query(value = "select * from matrix_version_history where relation_id = ?1 AND type = ?2 order by create_time DESC limit 0, 1", nativeQuery = true)
    VersionHistory findLatestVersionByRelationIdAndType(String relationId, String type);

    List<VersionHistory> findByRelationIdAndType(String relationId, String type);
}
